;
import express from "express";
import mysql from "mysql";
import cookieParser from "cookie-parser";
import cookieSesion from "cookie-session";
import bodyParser from "body-parser";
import {routes} from "./routes/apiRoute";

const app=express();
//配置中间键
app.use(bodyParser.urlencoded({
    extended:false
}));
app.use(bodyParser.json());
app.use(cookieParser("kazoo.cn"));
app.use(cookieSesion({
    name:"kazoo.cn",
    keys:["aaa","bbb","ccc"],
    expires:1000*60*10
}));
//搭建一个静态资源服务器
app.use(express.static("./public"));
//设置白名单
var whiteList=["/api/login","/api/reg","/api/goods","/api/isuname"];
//设置头
app.all("*",(req,res,next)=>{
    res.header("Content-Type","application/json;charset=utf-8");
    res.header("Access-Control-Allow-Origin","*");
    // console.log(req.originalUrl)
    // if(whiteList.indexOf(req.originalUrl)!=-1){
    //     next();
    // }else{
    //     res.status(505).json({
    //         "msg":"请您先登录",
    //         "status":-6
    //     });
    // }
    next()
})
//设置路由
app.use("/api",routes);
app.listen(8080,()=>{
    console.log("服务启动完毕~");
})